<template>
    <div class="bg-white">
        <nav class="border-b border-gray-100 bg-white">
            <div class="mx-auto flex h-16 max-w-7xl items-center justify-between px-4">
                <div class="flex items-center space-x-8">
                    <div class="flex-shrink-0">
                        <img :src="logoUrl" alt="Logo" class="h-8" />
                    </div>
                    <div class="flex items-center space-x-6">
                        <a v-for="(item, index) in navItems" :key="index" :class="[
                            'text-sm font-medium transition-colors duration-200',
                            route.path.indexOf(item.path) === 0 ? 'text-blue-600' : 'text-gray-600 hover:text-blue-600'
                        ]" @click="jump(item.path)">
                            <i :class="item.icon"></i>
                            {{ item.name }}
                        </a>
                    </div>
                </div>

                <div class="flex items-center space-x-6">
                    <!-- AI问答按钮 -->
                    <button
                        class="flex items-center space-x-1 text-sm text-gray-600 hover:text-blue-600 !rounded-button whitespace-nowrap"
                        @click="showAIChat = true">
                        <i class="iconfont icon-jiqiren_o" style="font-size: 1.5rem; color: #707070;"></i>>
                    </button>
                    <!-- 邮件中心 -->
                    <button
                        class="flex items-center space-x-1 text-sm text-gray-600 hover:text-blue-600 !rounded-button whitespace-nowrap"
                        @click="centerDialogVisible = true">
                        <el-icon>
                            <Message />
                        </el-icon>
                        <span v-if="unreadCount" class="ml-1 rounded-full bg-red-500 px-1.5 py-0.5 text-xs text-white">
                            {{ unreadCount }}
                        </span>
                    </button>
                    <!--签到-->
                    <button
                        class="flex items-center space-x-1 text-sm text-gray-600 hover:text-blue-600 !rounded-button whitespace-nowrap"
                        @click="jump('/signIn')">
                        <el-icon>
                            <Calendar />
                        </el-icon>
                    </button>
                    <button
                            class="flex items-center space-x-1 text-sm text-gray-600 hover:text-blue-600 !rounded-button whitespace-nowrap"
                            @click="jump('/position')">
                        <i class="iconfont icon-gangwei"></i>
                    </button>
                    <el-dropdown trigger="click">
                        <div class="flex cursor-pointer items-center space-x-3" @click="jump('/personalcenter')">
                            <div class="relative h-8 w-8 overflow-hidden rounded-full">
                                <img :src="avatarUrl" alt="用户头像" class="h-full w-full object-cover" />
                                <div v-if="isOnline"
                                    class="absolute bottom-0 right-0 h-2.5 w-2.5 rounded-full border-2 border-white bg-green-500">
                                </div>
                            </div>
                            <div class="flex items-center space-x-1">
                                <span class="text-sm font-medium">{{ userName }}</span>
                                <el-icon>
                                    <CaretBottom />
                                </el-icon>
                            </div>
                        </div>
                        <template #dropdown>
                            <el-dropdown-menu>
                                <el-dropdown-item v-for="(item, index) in dropdownItems" :key="index">
                                    <div class="flex items-center space-x-2">
                                        <el-icon>
                                            <component :is="item.icon" />
                                        </el-icon>
                                        <span @click="jump(item.path)">{{ item.label }}</span>
                                    </div>
                                </el-dropdown-item>
                            </el-dropdown-menu>
                        </template>
                    </el-dropdown>
                </div>
            </div>
        </nav>
        <!-- 邮件弹窗 -->
        <el-dialog v-model="centerDialogVisible" width="80%" align-center>
            <email></email>
        </el-dialog>

        <!-- AI问答弹窗 -->
        <el-dialog v-model="showAIChat" width="60%" class="ai-chat-dialog" :modal="true" :close-on-click-modal="false">
            <div class="relative">
                <button class="absolute top-2 right-2 text-gray-600" @click="showAIChat = false">
                    <i class="fas fa-times"></i>
                </button>
                <h3 class="text-xl font-semibold mb-4">AI问答</h3>
                <div class="ai-chat-content">
                    <!-- 在这里插入AI问答内容组件 -->
                    <aiChat></aiChat>
                </div>
            </div>
        </el-dialog>
    </div>
</template>
  
<script lang="ts" setup>
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { Message, Calendar, CaretBottom, SwitchButton } from '@element-plus/icons-vue';
import email from "../components/student/emailbox.vue";
import aiChat from "../components/student/aiChat.vue";

// 路由控制
const router = useRouter();
const route = useRoute();  // 使用useRoute获取当前路由路径

const logoUrl = 'https://ai-public.mastergo.com/ai/img_res/d332a5fc8a1321d8f02abf5aaf2dc5b8.jpg';
const avatarUrl = 'https://ai-public.mastergo.com/ai/img_res/256173fbe357dd1d88037ab9ae309e8d.jpg';

const isSignedIn = ref(false);
const unreadCount = ref(5);
const isOnline = ref(true);
const userName = ref('陈思远');
let centerDialogVisible = ref(false);
let showAIChat = ref(false);  // AI问答页面显示

const navItems = [
    { name: '素质报告', path: '/report', icon: 'iconfont icon-baogao' },
    { name: '认证中心', path: '/certificateAuthority', icon: 'iconfont icon-renzheng' },
    { name: '测评中心', path: '/assessment', icon: 'iconfont icon-zaixianceping' },
    { name: '简历中心', path: '/resume', icon: 'iconfont icon-resume-line' },
];

const dropdownItems = [
    { label: '个人中心', icon: 'User', path: '/personalcenter' },
    { label: '修改密码', icon: 'Edit', path: '/updatePassword' },
    { label: '退出登录', icon: 'SwitchButton', path: '/' },
];

function jump(path: string) {
    router.push(path);
}
</script>


<style scoped>
.rounded-button {
  border-radius: 999px;
}
.bg-white {
    --tw-bg-opacity: 1;
    background-color: rgb(255 255 255 / var(--tw-bg-opacity, 1));
    margin-bottom: 1px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
}

.duration-200 {
    transition-duration: 200ms;
    width: 180px;
}

/* 自定义AI问答弹窗背景虚化效果 */
.ai-chat-dialog .el-dialog__wrapper {
    backdrop-filter: blur(10px);
    /* 背景虚化 */
    background: rgba(255, 255, 255, 0.3);
    /* 半透明背景 */
}.max-w-7xl {
     max-width: 90rem;
 }
</style>
